<?php

namespace project\common;

use CoreDbRedis;
use CoreTraitRedisSet;
use IniReaderRedis;
use Redis;

class TaskSequence extends CoreDbRedis
{

    use CoreTraitRedisSet;

    private $taskSequence = 0;

    public function __construct()
    {
        $this->instance = $this->getRedis();
    }

    //注册事件
    //场景1. mysql 写入成功 + redis 写入成功; $task = ['mysql', 'redis']
    //场景2. 订单处理流程 + 创建订单 + 扣减库存 + 支付 + 发货 + 结算; $task = n
    //场景3. 异步消费 = 入队列 + 队列获取任务 + 执行
    public function register($task)
    {
        $this->taskSequence = $task;
    }

    public function record()
    {

    }

    public function exec($pos)
    {
        $this->taskSequence ^= $pos;
    }


    protected static function connect()
    {

    }

    public function __destruct()
    {
        parent::__destruct();
        //检查任务执行情况
        if (!empty($this->taskSequence)) {
            //记录任务完成情况 -> 完整的任务 + 未完成的任务
        }
    }

}